﻿// -----------------------------------------------------------------------
// <copyright file="RoundJob_DAL.cs" company="">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace PMSGSC.DAL
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public class RoundJob_DAL:BaseDAL
    {

        // Lấy tất cả RoundJob
        public static List<RoundJob> GetAll()
        {
            DB.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues, DB.RoundJobs);
            return DB.RoundJobs.ToList();
        }
        // Lấy RoundJob theo Id
        public static RoundJob GetDataById(RoundJob jp)
        {
            return DB.RoundJobs.Where(m => m.Round_ID == jp.Job_ID && m.Job_ID == jp.Job_ID).FirstOrDefault();
        }
        //Thêm một RoundJob
        public static bool Insert(RoundJob RoundJob)
        {
            try
            {
                DB.RoundJobs.InsertOnSubmit(RoundJob);
                DB.SubmitChanges();
                return true;
            }
            catch
            {
                return false;
            }

        }
        // Xóa một RoundJob
        public static bool Delete(RoundJob RoundJob)
        {
            try
            {
                DB.RoundJobs.DeleteOnSubmit(RoundJob);
                DB.SubmitChanges();
                return true;
            }
            catch
            {
                return false;
            }

        }
        public static bool DeleteByID(RoundJob jp)
        {
            RoundJob objRoundJob = GetDataById(jp);
            return Delete(objRoundJob);
        }
        // Cập nhật RoundJob
        public static bool Update(RoundJob RoundJob)
        {
            try
            {
                RoundJob objRoundJob = GetDataById(RoundJob);
                objRoundJob.Job_ID = RoundJob.Job_ID;
                objRoundJob.Round_ID = RoundJob.Round_ID;
                objRoundJob.ComponentCode = RoundJob.ComponentCode;
                objRoundJob.ComponentName = RoundJob.ComponentName;
                objRoundJob.JobCode = RoundJob.JobCode;
                objRoundJob.JobDescription = RoundJob.JobDescription;
                objRoundJob.Revision = RoundJob.Revision;
                DB.SubmitChanges();
                return true;
            }
            catch
            {
                return false;
            }

        }
        public static bool isExits(RoundJob jp)
        {
            RoundJob objPartJob = null;
            objPartJob = DB.RoundJobs.Where(j => ((j.Job_ID == jp.Job_ID) &&
                (j.Round_ID == jp.Round_ID))).FirstOrDefault();
            return objPartJob != null ? true : false;
        }
        public static List<RoundJob> GetDataByRoundID(int id, bool ischanged)
        {
            if (ischanged)
            {
                DB.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues, DB.RoundJobs);
            }
            return DB.RoundJobs.Where(j => j.Round_ID == id).ToList();
        }
    }
}
